﻿{
    

    $project:
        {
            
            _id: "$_id",
            CompanyId: "$CompanyId",
            MatrixId: "$MatrixId",
            PeerGroupId: "$PeerGroupId",
            ParentGroupId: "$ParentGroupId",
            PeerGroupName: "$PeerGroupName",
            WorkingVersion : "$WorkingVersion",
            CompanyName : "$CompanyName ",



            E: "$E",
            S: "$S",
            G: "$G",
            P: "$P",


            E_1: {
                Weight: "$E_1.Weight",
                Score: {
                    $add: [                          
                          { $ifNull: [{ $multiply: ['$E_1_1_1.Score', '$E_1_1_1.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_2.Score', '$E_1_2.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_2_1.Score', '$E_1_2_1.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_2_2.Score', '$E_1_2_2.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_2_3.Score', '$E_1_2_3.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_2_4.Score', '$E_1_2_4.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_2_6.Score', '$E_1_2_6.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_2_7.Score', '$E_1_2_7.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_2_8.Score', '$E_1_2_8.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_3.Score', '$E_1_3.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_3_2.Score', '$E_1_3_2.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_3_3.Score', '$E_1_3_3.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_3_4.Score', '$E_1_3_4.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_3_5.Score', '$E_1_3_5.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_4.Score', '$E_1_4.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_5.Score', '$E_1_5.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_6.Score', '$E_1_6.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_7.Score', '$E_1_7.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_7_1.Score', '$E_1_7_1.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_7_2.Score', '$E_1_7_2.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_8.Score', '$E_1_8.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_9.Score', '$E_1_9.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_10.Score', '$E_1_10.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_11.Score', '$E_1_11.Weight'] }, 0] },
                          { $ifNull: [{ $multiply: ['$E_1_12.Score', '$E_1_12.Weight'] }, 0] },
                    ]
                }
            },
            E_2: {
                    Weight: "$E_2.Weight",
                    Score: {
                    $add: [
                             { $ifNull: [{ $multiply: ['$E_2_1.Score', '$E_2_1.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_2_1_1.Score', '$E_2_1_1.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_2_1_2.Score', '$E_2_1_2.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_2_1_3.Score', '$E_2_1_3.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_2_1_4.Score', '$E_2_1_4.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_2_1_5.Score', '$E_2_1_5.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_2_1_6.Score', '$E_2_1_6.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_2_1_7.Score', '$E_2_1_7.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_2_1_8.Score', '$E_2_1_8.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_2_1_9.Score', '$E_2_1_9.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_2_1_10.Score', '$E_2_1_10.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_2_2.Score', '$E_2_2.Weight'] }, 0] },
                    ]
                    }
            },

            E_3: {
                    Weight: "$E_3.Weight",
                    Score: {
                    $add: [
                             { $ifNull: [{ $multiply: ['$E_3_1_1.Score', '$E_3_1_1.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_3_1_2.Score', '$E_3_1_2.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_3_1_3.Score', '$E_3_1_3.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_3_1_4.Score', '$E_3_1_4.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_3_1_5.Score', '$E_3_1_5.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_3_1_6.Score', '$E_3_1_6.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_3_1_7.Score', '$E_3_1_7.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_3_1_8.Score', '$E_3_1_8.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_3_1_9.Score', '$E_3_1_9.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_3_1_10.Score', '$E_3_1_10.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_3_1_11.Score', '$E_3_1_11.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_3_1_12.Score', '$E_3_1_12.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_3_1_13.Score', '$E_3_1_13.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_3_1_14.Score', '$E_3_1_14.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_3_1_15.Score', '$E_3_1_15.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_3_1_16.Score', '$E_3_1_16.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_3_1_17.Score', '$E_3_1_17.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$E_3_2.Score', '$E_3_2.Weight'] }, 0] },

                    ]
                    }
            },




            G_1: {
                    Weight: "$G_1.Weight",
                    Score: {
                    $add: [
                         { $ifNull: [{ $multiply: ['$G_1_1.Score', '$G_1_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_1_1_1.Score', '$G_1_1_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_1_2.Score', '$G_1_2.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_1_3.Score', '$G_1_3.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_1_3_1.Score', '$G_1_3_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_1_3_2.Score', '$G_1_3_2.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_1_3_3.Score', '$G_1_3_3.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_1_3_4.Score', '$G_1_3_4.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_1_3_5.Score', '$G_1_3_5.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_1_4.Score', '$G_1_4.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_1_4_1.Score', '$G_1_4_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_1_4_3.Score', '$G_1_4_3.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_1_4_4.Score', '$G_1_4_4.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_1_4_5.Score', '$G_1_4_5.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_1_4_6.Score', '$G_1_4_6.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_1_5.Score', '$G_1_5.Weight'] }, 0] },
                    ]
                    }
            },
            G_2: {
                    Weight: "$G_2.Weight",
                    Score: {
                    $add: [
                             { $ifNull: [{ $multiply: ['$G_2_1.Score', '$G_2_1.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$G_2_2.Score', '$G_2_2.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$G_2_3.Score', '$G_2_3.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$G_2_4.Score', '$G_2_4.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$G_2_5.Score', '$G_2_5.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$G_2_5_1.Score', '$G_2_5_1.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$G_2_6.Score', '$G_2_6.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$G_2_7.Score', '$G_2_7.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$G_2_8.Score', '$G_2_8.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$G_2_9.Score', '$G_2_9.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$G_2_10.Score', '$G_2_10.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$G_2_11.Score', '$G_2_11.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$G_2_12.Score', '$G_2_12.Weight'] }, 0] },
                             { $ifNull: [{ $multiply: ['$G_2_13.Score', '$G_2_13.Weight'] }, 0] },
                    ]
                    }
            },

            G_3: {
                    Weight: "$G_3.Weight",
                    Score: {
                    $add: [
                         { $ifNull: [{ $multiply: ['$G_3_1.Score', '$G_3_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_3_2.Score', '$G_3_2.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_3_3_1.Score', '$G_3_3_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$G_3_4.Score', '$G_3_4.Weight'] }, 0] },
                    ]
                    }
            },
            S_1: {
                    Weight: "$S_1.Weight",
                    Score: {
                    $add: [
                         { $ifNull: [{ $multiply: ['$S_1_1.Score', '$S_1_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_1_1_1.Score', '$S_1_1_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_1_2.Score', '$S_1_2.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_1_3.Score', '$S_1_3.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_1_4.Score', '$S_1_4.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_1_5.Score', '$S_1_5.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_1_5_1.Score', '$S_1_5_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_1_6.Score', '$S_1_6.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_1_6_1.Score', '$S_1_6_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_1_6_2.Score', '$S_1_6_2.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_1_6_3.Score', '$S_1_6_3.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_1_6_4.Score', '$S_1_6_4.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_1_6_5.Score', '$S_1_6_5.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_1_6_6.Score', '$S_1_6_6.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_1_7.Score', '$S_1_7.Weight'] }, 0] },
                    ]
                    }
            },
            S_2: {
                    Weight: "$S_2.Weight",
                    Score: {
                    $add: [
                         { $ifNull: [{ $multiply: ['$S_2_1.Score', '$S_2_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_2_1_1.Score', '$S_2_1_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_2_1_2.Score', '$S_2_1_2.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_2_1_3.Score', '$S_2_1_3.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_2_2.Score', '$S_2_2.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_2_2_1.Score', '$S_2_2_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_2_2_2.Score', '$S_2_2_2.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_2_2_3.Score', '$S_2_2_3.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_2_2_4.Score', '$S_2_2_4.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_2_3.Score', '$S_2_3.Weight'] }, 0] },
                    ]
                    }
            },

            S_3: {
                    Weight: "$S_3.Weight",
                    Score: {
                    $add: [
                         { $ifNull: [{ $multiply: ['$S_3_1_1.Score', '$S_3_1_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_3_1_2.Score', '$S_3_1_2.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_3_1_3.Score', '$S_3_1_3.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_3_1_4.Score', '$S_3_1_4.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_3_1_5.Score', '$S_3_1_5.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_3_1_6.Score', '$S_3_1_6.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_3_1_7.Score', '$S_3_1_7.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_3_1_8.Score', '$S_3_1_8.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_3_1_9.Score', '$S_3_1_9.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_3_1_10.Score', '$S_3_1_10.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_3_1_11.Score', '$S_3_1_11.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_3_1_12.Score', '$S_3_1_12.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_3_2_1.Score', '$S_3_2_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_3_3.Score', '$S_3_3.Weight'] }, 0] },
                    ]
                    }
            },
            S_4: {
                    Weight: "$S_4.Weight",
                    Score: {
                    $add: [
                         { $ifNull: [{ $multiply: ['$S_4_1.Score', '$S_4_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_4_2_1.Score', '$S_4_2_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_4_2_2.Score', '$S_4_2_2.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_4_2_3.Score', '$S_4_2_3.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_4_2_4.Score', '$S_4_2_4.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_4_2_5.Score', '$S_4_2_5.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_4_2_6.Score', '$S_4_2_6.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_4_2_7.Score', '$S_4_2_7.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_4_2_8.Score', '$S_4_2_8.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_4_2_9.Score', '$S_4_2_9.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_4_2_10.Score', '$S_4_2_10.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_4_2_11.Score', '$S_4_2_11.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_4_2_12.Score', '$S_4_2_12.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_4_2_13.Score', '$S_4_2_13.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_4_2_14.Score', '$S_4_2_14.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_4_3.Score', '$S_4_3.Weight'] }, 0] },
                    ]
                    }
            },
            S_5: {
                    Weight: "$S_5.Weight",
                    Score: {
                    $add: [
                         { $ifNull: [{ $multiply: ['$S_5_1.Score', '$S_5_1.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_5_2.Score', '$S_5_2.Weight'] }, 0] },
                         { $ifNull: [{ $multiply: ['$S_5_3.Score', '$S_5_3.Weight'] }, 0] },
                    ]
                    }
            },
            }
}